#define DEBUG
#include <cstdio>
#define MODS 1000000007
#define MAXN 100000
#define MAXM 100000

using namespace std;

int getFa(int *a, int o) {
  if (a[o]!=o) {
    a[o] = getFa(a, a[o]);
  }
  return a[o];
}

int main() {
#ifdef DEBUG
  freopen("2.in", "r", stdin);
  freopen("2.out", "w", stdout);
#endif

  static int node[MAXN+1];
  static bool book[MAXN+1];
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i=1; i<=n; i++) {
    node[i]=i;
  }
  for (int i=1; i<=m; i++) {
    int l1, r1, l2, r2;
    scanf("%d %d %d %d", &l1, &r1, &l2, &r2);
    for (int j=0; j<=r1-l1; j++) {
      if (getFa(node, l1+j)!=getFa(node, l2+j)) {
	node[getFa(node, l1+j)]=getFa(node, l2+j);
      }
    }
  }

  long long ans=9;
  book[getFa(node, 1)]=true;
  for (int i=2; i<=n; i++) {
    if (!book[getFa(node, i)]) {
      ans = ans*10%MODS;
      book[getFa(node, i)]=true;
    }
  }
  printf("%lld", ans);

  fclose(stdin);
  fclose(stdout);
}
